package com.xiaoai.httpClientTestService.httpclient.one;

import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.ParseException;
import org.apache.hc.core5.http.io.entity.EntityUtils;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class HttpclientDemo {
    
    public static void main(String[] args) throws IOException, ParseException {
        RequestConfig requestConfig = RequestConfig.custom()
                .setConnectTimeout(30, TimeUnit.SECONDS)
                .setConnectionRequestTimeout(10,TimeUnit.SECONDS)
                .setResponseTimeout(10,TimeUnit.SECONDS)
                .build();


        CloseableHttpClient aDefault = HttpClients.createDefault();

        HttpGet httpGet = new HttpGet("http://www.baidu.com");
        httpGet.setConfig(requestConfig);

        CloseableHttpResponse response = aDefault.execute(httpGet);

        System.out.println("响应码："+response.getCode());
        HttpEntity entity = response.getEntity();
        System.out.println("实体"+ entity);

        String s = EntityUtils.toString(entity);

        System.out.println(s);




    }
    
    
}
